package at.fht.bwi.sem5.view;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import at.fht.bwi.sem5.R;
import at.fht.bwi.sem5.domain.Buschenschank;
import at.fht.bwi.sem5.map.BuschenschankReader;
import at.fht.bwi.sem5.map.CustomOverlay;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class MainMapView extends MapActivity {

 
	private MapView mapView;
	private MapController mapController;
	GeoPoint geoPoint;
	
@Override	
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     
     //setting the Content view
     setContentView(R.layout.mainmapview);
     
     //catching the view from resource
     mapView = (MapView) findViewById(R.id.mapview);
    
     
     mapView.setBuiltInZoomControls(true);
     
     Drawable drawable = this.getResources().getDrawable(R.drawable.buschenschank_icon);
     
     CustomOverlay customOverlay =new CustomOverlay(drawable, this);

     
     mapController = mapView.getController();
     
  
     
     
     CustomOverlay itemizedoverlay = new CustomOverlay(drawable,this);
     
     
     List<Buschenschank> buschenschankList = BuschenschankReader.readBuschenschaenke(getResources().getXml(R.xml.buschenschaenke));
     OverlayItem overlayitem = null;
     for (Buschenschank buschenschank : buschenschankList) {
    	   int latitude  = (int) (buschenschank.getCoordinates().getLatitudes() * 1E6);
    	   int longitude = (int) (buschenschank.getCoordinates().getLongitude() * 1E6);
    	   geoPoint = new GeoPoint(latitude, longitude);
    	   
    	   overlayitem =new OverlayItem(geoPoint, buschenschank.getName(), buschenschank.getAddress().toString());
    	   customOverlay.addOverlay(overlayitem);
	}
     
     List<Overlay> mapOverlays = mapView.getOverlays();
     mapOverlays.add(customOverlay);
     
    //center to Hartberg
    int latitude  = (int) (new Double(47.292271) * 1E6);
    int longitude = (int) (new Double(15.979614 ) * 1E6);
    geoPoint = new GeoPoint(latitude, longitude);
     
    mapController.animateTo(geoPoint);
    mapController.setZoom(14);       
          

 }
 
 @Override
 protected boolean isRouteDisplayed() {
   return false;
 }
}